package view;


import controller.UnblockUserController;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class UnblockUserView {
    private final UnblockUserController controller = new UnblockUserController();

    public void showUi() {
        JFrame jf = new JFrame("解除用户屏蔽");
        jf.setIconImage(Toolkit.getDefaultToolkit().createImage(MainView.class.getResource("qq.jpg")));
        JPanel jp = new JPanel();
        JLabel jl1 = new JLabel("选择需解除屏蔽的用户");
        jl1.setFont(new Font("黑体", Font.BOLD, 24));
        JButton bu1 = new JButton("确      认");
        JButton bu4 = new JButton("退      出");
        String[] users = controller.getUsers();
        JComboBox<String> comboBox = new JComboBox<>(users);
        jp.setLayout(null);
        jl1.setBounds(125, 1, 300, 50);
        comboBox.setBounds(150, 100, 150, 50);
        bu1.setBounds(150, 200, 150, 50);
        bu4.setBounds(150, 300, 150, 50);
        jp.add(jl1);
        jf.add(bu1);
        jf.add(bu4);
        jf.add(comboBox);
        jf.add(jp);
        jf.setVisible(true);
        jf.setBounds(600, 200, 500, 500);
        bu1.addActionListener(e -> {
            Object selectedItem = comboBox.getSelectedItem();
            boolean b = controller.unblockUser(selectedItem);
            if (b) {
                JOptionPane.showMessageDialog(null, "解除屏蔽成功！！！");
            } else {
                JOptionPane.showMessageDialog(null, "该用户已被解除屏蔽！！！");
            }
        });
        bu4.addActionListener(e -> jf.dispose());
        jf.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                jf.dispose();
            }
        });
    }
}